import { Component, OnInit } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { AppPaginationComponent, PaginationModel } from "../../../../../widgets/pagination/pagination.component";
import { EditService } from './edit.service'

@Component({
  selector: 'app-edit',
  templateUrl: './edit.component.html',
  styleUrls: ['./edit.component.scss'],
  providers: [EditService]
})
export class EditComponent implements OnInit {
  //modal创建时传值
  public item: any;

  //列表数据
  public listData: any = [];

  constructor(
    public editService: EditService,
  ) { }

  ngOnInit() {
    console.log(this.item.sMemberFundnos);
    this.loadlist();

  }
  //分页配置
  public listPageInfo = {
    currentPageNum: 1,
    pageSize: 50,
    totalPages: 1,
    total: 0,
    pagesShow: 5,
    startRow: 0,
    endRow: 0,
    pageList: [5, 10, 25, 50, 100]
  };

  //分页列表
  loadlist(pageNum?, pageSize?) {
    let that = this;
    //查询列表getBody
    let getBody: any = {
      pageIndex: 1,
      pageSize: 50,
      // nFgId: this.item.nFgId,
      sType: this.item.sType,
      sFgName: this.item.sFgName,
      nFundNos: this.item.sMemberFundnos
    };
    getBody.pageIndex = pageNum ? pageNum : this.listPageInfo.currentPageNum;
    getBody.pageSize = pageSize ? pageSize : this.listPageInfo.pageSize;
    this.editService.edit(getBody).subscribe(data => {
      if (data) {
        console.log(data);
        this.listData = data.list;
        console.log(data.list);
        this.listPageInfo.currentPageNum = data.pageNum;
        this.listPageInfo.totalPages = data.pages;
        this.listPageInfo.total = data.total;
        this.listPageInfo.startRow = data.startRow;
        this.listPageInfo.endRow = data.endRow;
      }
    })
  }

  // 条数分页
  sizeChange(pageSize: number) {
    if (pageSize !== this.listPageInfo.pageSize) {
      this.listPageInfo.pageSize = pageSize;
      this.loadlist();
    }
  }
  // 列表分页
  pageNavigation(currentPageNum: number) {
    this.listPageInfo.currentPageNum = currentPageNum;
    this.loadlist(this.listPageInfo.currentPageNum, this.listPageInfo.pageSize);
  }

}
